<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">档案编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">档案名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">归档日期</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="dt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">归档人</label>
                        <div class="layui-input-block">
                            <input type="text" name="baner" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">存放位置</label>
                        <div class="layui-input-block">
                            <div id="dangcun" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">是否可借阅</label>
                        <div class="layui-input-block">
                            <select name="isjie" lay-filter="isjie" >
                                <option value="">请选择</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="dangtype" name="dangtype" value="">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md2" id="navselect">
                <div class="navselect_bac">
                    <div class="navselect_div">
                        <div class="navselect_title">档案分类</div>
                        <div class="navselect_nav">
                            <a id="tree_pand" title="收起/展开">收起</i></a>&nbsp;
                            <a id="tree_search" title="刷新"><i class="layui-icon layui-icon-refresh-1"></i></a>
                        </div>
                    </div>
                    <div>
                        <button type="button" class="layui-btn layui-btn-sm typeall">
                        <i class="layui-icon layui-icon-home"></i>&nbsp;&nbsp;&nbsp;全部
                        </button>
                    </div>
                    <div id="tree_content"></div>
                </div>
            </div>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var currButAuth, currTabData, mytable, table, form, treeObj, deptTreeStatus=1,deptTreeData=[];
    layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        getDeptData();
        $("#tree_search").click(function () {
            getDeptData();
        });
        $('#tree_pand').click(function () {
            if(deptTreeStatus == 1){
                treeObj.reload({id: 'deptTree',data: opt_tree(deptTreeData, false)});
                deptTreeStatus = 2;
                $("#tree_pand").html('展开');
            }else{
                treeObj.reload({id: 'tree_content',data: opt_tree(deptTreeData, true)});
                deptTreeStatus = 1;
                $("#tree_pand").html('收起');
            }
        });
        function getDeptData() {
            facade.ajax({url: ask_dangtype_list}).done(function(res){
                if (res.code === 2000) {
                    deptTreeData = res.data;
                    deptTreeStatus = 2;
                    $("#tree_pand").html('展开');
                    treeObj = tree.render({
                        elem: '#tree_content'
                        ,id: 'tree_content'
                        ,data: deptTreeData
                        ,onlyIconControl: true
                        ,click: function(obj){
                            if(obj.data.id && obj.data.id > 0){
                                $("#dangtype").val(obj.data.value)
                                searchTableFunc(form, table);

                                $('.layui-tree-entry').each(function () {
                                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
                            });
                            $(obj.elem).find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
                            }
                        }
                    });
                    var height = $('.laytp-container').height() - 220 + 'px';
                    $('#tree_content').css('cssText','max-height:'+height);
                }
            });
        }

        $('.typeall').click(function () {
            $('.layui-tree-entry').each(function () {
                $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
            });
            $("#dangtype").val(0)
            searchTableFunc(form, table);
        });



        setSouTableExport('档案库');
        mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_dang_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                xmselect_dan('dangcun', res.data.dangcun, res.data.is_dangcun, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'number', title: '档案编号'}
                ,{field: 'dangtype', title: '所属分类'}
                ,{field: 'name', title: '档案名称'}
                ,{field: 'num', title: '归档份数'}
                ,{field: 'dt', title: '归档日期'}
                ,{field: 'baner', title: '归档人'}
                ,{field: 'dangcun', title: '存放位置'}
                ,{field: 'isjie', title: '是否可借阅'}
                ,{field: 'jienum', title: '在借份数'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_dang_del, {id:trData.id});
    }







    function opt_tree(data, status) {
        for (var i=0;i<data.length;i++){
            data[i]['spread'] = status;
            if(data[i].children != undefined){
                opt_tree(data[i].children, status);
            }
        }
        return data;
    }

</script>
</body>
</html>
